import request from '@/utils/http.js'

const appkey = 'U2FsdGVkX19WSQ59Cg+Fj9jNZPxRC5y0xB1iV06BeNA='
 
/* 
 获取购物车数据
 params = {
	 appkey,
	 tokenString
 }
 */

export const getShopCart = (params) => {
	if(!params) {
		params = { appkey }
	} else {
		params['appkey'] = appkey
	}
	return request({
		method: 'GET',
		url: '/findAllShopcart',
		params
	})
}

/* 
 获取购物车条数
 params = {
	 appkey,
	 tokenString
 }
 */

export const getShopCartLength = (params) => {
	if(!params) {
		params = { appkey }
	} else {
		params['appkey'] = appkey
	}
	return request({
		method: 'GET',
		url: '/shopcartRows',
		params
	})
}

/* 
 添加购物车
 params = {
	 appkey,
	 tokenString,
	 pid,  //产品id
	 count,  //产品数量
	 rule  //商品规格
 }
 */

export const addShopCart = (data) => {
	if(!data) {
		data = { appkey }
	} else {
		data['appkey'] = appkey
	}
	return request({
		method: 'POST',
		url: '/addShopcart',
		data
	})
}


/* 
 获取我的订单
 params = {
	 appkey,
	 tokenString,
	 status
	 其中 status 值为 0, 1, 2 ==> 0: 全部，1: 进行中，2: 已完成
 }
 */

export const getOrder = (params) => {
	if(!params) {
		params = { appkey }
	} else {
		params['appkey'] = appkey
	}
	return request({
		method: 'GET',
		url: '/findOrder',
		params
	})
}

/* 
 确定收货
 data = {
	 appkey,
	 tokenString,
	 oid // 订单编号
 }
 */

export const receive = (data) => {
	if(!data) {
		data = { appkey }
	} else {
		data['appkey'] = appkey
	}
	return request({
		method: 'POST',
		url: '/receive',
		data
	})
}

/* 
 移除订单
 data = {
	 appkey,
	 tokenString,
	 oid // 订单编号
 }
 */

export const removeOrder = (data) => {
	if(!data) {
		data = { appkey }
	} else {
		data['appkey'] = appkey
	}
	return request({
		method: 'POST',
		url: '/removeOrder',
		data
	})
}

/* 
 移除购物车
 data = {
	 appkey,
	 tokenString,
	 sids // 购物车编号 多个订单已数组形式 以（-）分割  （数组字符串）
 }
 */

export const removeShopCart = (data) => {
	if(!data) {
		data = { appkey }
	} else {
		data['appkey'] = appkey
	}
	return request({
		method: 'POST',
		url: '/deleteShopcart',
		data
	})
}

/* 
 购物车商品数量增减
 data = {
	 appkey,
	 tokenString,
	 sid,
	 count
 }
 */

export const changeSCC = (data) => {
	if(!data) {
		data = { appkey }
	} else {
		data['appkey'] = appkey
	}
	return request({
		method: 'POST',
		url: '/modifyShopcartCount',
		data
	})
}

/* 
 获取地址
 data = {
	 appkey,
	 tokenString
 }
 */

export const getAddress = (params) => {
	if(!params) {
		params = { appkey }
	} else {
		params['appkey'] = appkey
	}
	return request({
		method: 'GET',
		url: '/findAddress',
		params
	})
}

/* 
 提交订单购物车商品查询
 data = {
	 appkey,
	 tokenString,
	 sids  购物车编号 多个订单已数组形式 以（-）分割 （数组字符串）
 }
 */

export const getCommitShopCart = (params) => {
	if(!params) {
		params = { appkey }
	} else {
		params['appkey'] = appkey
	}
	return request({
		method: 'GET',
		url: '/commitShopcart',
		params
	})
}

/* 
 提交订单
 data = {
	 appkey,
	 tokenString,
	 sids,  购物车编号 多个订单已数组形式 以（-）分割 （数组字符串）
	 phone,
	 address,
	 receiver
 }
 */

export const pay = (data) => {
	if(!data) {
		data = { appkey }
	} else {
		data['appkey'] = appkey
	}
	return request({
		method: 'POST',
		url: '/pay',
		data
	})
}


/* 
	新建/编辑地址 url（/addAddress）（/editAddress）
	data = {
	 appkey,
	 tokenString,
	 name,
	 tel,
	 country, 
	 province,
	 city,
	 county,
	 areaCode,
	 postalCode,
	 addressDetail,
	 isDefault,
	 id,
	 aid,
	 userId,
	 isRemove,
	 createdAt,
	 updatedAt
 } 
*/

export const address = (url,data) => {
	if(!data) {
		data = { appkey }
	} else {
		data['appkey'] = appkey
	}
	return request({
		method: 'POST',
		url,
		data
	})
}

 
/* 
 根据aid获取地址信息
 params = {
	 appkey,
	 tokenString,
	 aid
 }
 */

export const getAddressByAid= (params) => {
	if(!params) {
		params = { appkey }
	} else {
		params['appkey'] = appkey
	}
	return request({
		method: 'GET',
		url: '/findAddressByAid',
		params
	})
}

/* 
 移除地址
 data = {
	 appkey,
	 tokenString,
	 aid
 }
 */

export const removeAddress = (data) => {
	if(!data) {
		data = { appkey }
	} else {
		data['appkey'] = appkey
	}
	return request({
		method: 'POST',
		url: '/deleteAddress',
		data
	})
}